package com.ytjj.qmyx.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.ytjj.common.api.CommonPage;
import com.ytjj.qmyx.admin.mapper.PushMessageMapper;
import com.ytjj.qmyx.admin.model.PushMessage;
import com.ytjj.qmyx.admin.model.response.PushMessagePro;
import com.ytjj.qmyx.admin.model.vo.PushMessageVO;
import com.ytjj.qmyx.admin.service.PushMessageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PushMessageServiceImpl implements PushMessageService {

    @Resource
    private PushMessageMapper pushMessageMapper;

    @Override
    public CommonPage selectPushMessagePage(PushMessagePro pushMessagePro) {
        PageHelper.startPage(pushMessagePro.getPageNum(),pushMessagePro.getPageSize());
        CommonPage page = CommonPage.restPage(pushMessageMapper.selectPushMessagePage(pushMessagePro));
        return page;
    }

    @Override
    public int insertPushMessage(List<PushMessage> pushMessage) {
            for (PushMessage pushMessage1: pushMessage) {
                int pushId = pushMessageMapper.insertPushMessage(pushMessage1);
                pushMessageMapper.insertMessageBodyList(pushMessage1.getMessageBody(), pushMessage1.getId());
            }
        return 0;
    }

    @Override
    public List<PushMessageVO> PushMessage(Integer messageTypeId) {
        return pushMessageMapper.PushMessage(messageTypeId);
    }

    @Override
    public int updatePushMessage(PushMessage pushMessage) {
        pushMessageMapper.updatePushMessage(pushMessage);
        pushMessageMapper.updateMessageBody(pushMessage.getMessageBody());
        return 0;
    }

    @Override
    public PushMessageVO selectPushMessage(Integer id) {
        return pushMessageMapper.selectPushMessage(id);
    }

}
